//
//  ZSY_UserTableViewCell.m
//  ZSY_BreadTrip
//
//  Created by 张诗宇 on 15/12/29.
//  Copyright © 2015年 张诗宇. All rights reserved.
//

#import "ZSY_UserTableViewCell.h"

@interface ZSY_UserTableViewCell ()

@property (nonatomic, retain) ZSY_BaseLabel *titleLabel;
@property (nonatomic, retain) ZSY_BaseImageView *coverImageView;
@property (nonatomic, retain) ZSY_BaseImageView *avatarImageView;

@property (nonatomic, retain) ZSY_BaseLabel *tabLabel; // 用数组循环铺

@property (nonatomic, retain) ZSY_BaseLabel *dateLabel;
@property (nonatomic, retain) ZSY_BaseLabel *addressLabel;
@property (nonatomic, retain) ZSY_BaseLabel *like_countLabel;

@property (nonatomic, retain) ZSY_BaseLabel *priceLabel;
@property (nonatomic, retain) CAGradientLayer *gradientLayer;


@end

@implementation ZSY_UserTableViewCell
- (void)dealloc {
    [_tabLabel release];
    [_addressLabel release];
    [_priceLabel release];
    [_dateLabel release];
    [_titleLabel release];
    [_like_countLabel release];
    [_coverImageView release];
    [_avatarImageView release];
    [super dealloc];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-  (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)setCity:(ZSY_CityModel *)city {
    if (_city != city) {
        [_city release];
        _city = [city retain];
        NSURL *coverUrl = [NSURL URLWithString:_city.title_page];
        [self.coverImageView sd_setImageWithURL:coverUrl];
        
//        NSURL *userUrl = [NSURL URLWithString:_city.userModel.avatar_l];
//        [self.avatarImageView sd_setImageWithURL:userUrl placeholderImage:nil];
        
        self.titleLabel.text = _city.title;
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        self.titleLabel.numberOfLines = 0;
        [self.titleLabel sizeToFit];
        
        
//        self.addressLabel.text = _city.address;
//        self.addressLabel.font = [UIFont systemFontOfSize:11];
//        [self.addressLabel sizeToFit];
//        self.addressLabel.textColor = [UIColor lightGrayColor];
        
//        self.priceLabel.text = [NSString stringWithFormat:@"¥ %@", _city.price];
//        self.priceLabel.font = [UIFont systemFontOfSize:20];
//        self.priceLabel.textAlignment = NSTextAlignmentCenter;
//        self.priceLabel.textColor = [UIColor redColor];
        
    }
    
}

- (void)createSubviews {
    //    self.contentView.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:243 / 255.0 blue:233 / 255.0 alpha:1];
    
    ZSY_BaseView *backView = [[ZSY_BaseView alloc] initWithFrame:CGRectMake(10, 10, WIDTH - 20, 310)];
//    [self.contentView addSubview:backView];
    
    backView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    backView.layer.borderWidth = 1;
    backView.layer.cornerRadius = 5;
    backView.layer.masksToBounds = YES;
    
    self.coverImageView = [[ZSY_BaseImageView alloc] initWithFrame:CGRectMake(10, 10, WIDTH - 20, 190)];
    self.coverImageView.backgroundColor = [UIColor lightGrayColor];
    self.coverImageView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.coverImageView.layer.borderWidth = 1;
    self.coverImageView.layer.cornerRadius = 5;
    self.coverImageView.layer.masksToBounds = YES;
    [self.contentView addSubview:_coverImageView];
    
    // 设置渐变色
    self.gradientLayer = [CAGradientLayer layer];
    self.gradientLayer.frame = self.coverImageView.bounds;
    [self.coverImageView.layer addSublayer:self.gradientLayer];
    self.gradientLayer.startPoint = CGPointMake(0, 0);
    self.gradientLayer.endPoint = CGPointMake(0, 1);
    self.gradientLayer.colors = @[(__bridge id)[UIColor blackColor].CGColor, (__bridge id)[UIColor clearColor].CGColor];
    self.gradientLayer.locations = @[@(0.0001f), @(1.0f)];
    
    
    self.titleLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(10, 10, WIDTH - 150, 40)];
    //    self.titleLabel.backgroundColor = [UIColor blueColor];
    self.titleLabel.textColor = [UIColor whiteColor];
    [_coverImageView addSubview:_titleLabel];
    [_titleLabel release];
    
    self.avatarImageView = [[ZSY_BaseImageView alloc] initWithFrame:CGRectMake(WIDTH - 100, 160, 50, 50)];
    self.avatarImageView.layer.borderWidth = 2;
    self.avatarImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    self.avatarImageView.layer.cornerRadius = 25;
    self.avatarImageView.layer.masksToBounds = YES;
    self.avatarImageView.backgroundColor = [UIColor blackColor];
//    [self.coverImageView addSubview:_avatarImageView];
    [_avatarImageView release];
    
    self.addressLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake(10, 150, WIDTH - 80, 10)];
//    [_coverImageView addSubview:_addressLabel];
    [_addressLabel release];
    
    self.priceLabel = [[ZSY_BaseLabel alloc] initWithFrame:CGRectMake((WIDTH - 20) / 2, 150, (WIDTH - 20) / 2, 40)];
//    [_coverImageView addSubview:_priceLabel];
    [_priceLabel release];
    [_coverImageView release];
}


@end
